Page({
    data: {
      list: [],
      userId: '',
      userInfo: null,
      wordList: [],
    },
    
    onLoad: function(options) {
        var userInfo = wx.getStorageSync('userInfo');
        this.setData({ userInfo: userInfo });
        console.log(this.data.userInfo)
        this.leftSlideGroup = this.selectComponent("#leftSlideGroup")
        var that = this
        //var userId = wx.getStorageSync('userId');
        //this.setData({
        //  userId: userId,
        //})

        wx.request({
            url: 'http://47.95.223.130:8083/Custom/request',
            method: 'GET',
            data: { userId: that.data.userInfo.uuid },
            success: function(res) {
                if (res.data.code === 200) {
                    var dataList = res.data.data;
                    var transformedData = [];
                    dataList.forEach(function(item) {
                        var parsedWord = JSON.parse(item.word);
                        parsedWord.word_id = item.word_id;
                        transformedData.push(parsedWord);
                    });
                    that.setData({
                        list: dataList,
                        wordList: transformedData    // 存储的就是转换后的新的数组
                    });
                    console.log(that.data.list);
                    console.log(that.data.wordList);
                }
            },
            fail: function(err) {
                console.log(err)
            }
        });
    
        //... 下面的操作
    },


    toWordDetail: function(e) {
        var index = e.currentTarget.dataset.index
        // 获取当前页面序号对应的数据
        var dataToStore = this.data.wordList[index];
        // 存储到微信的缓存中
        try {
          wx.setStorageSync('WordDetail', dataToStore);
        //   wx.navigateTo({
        //     url: '/path/WordDetail/WordDetail', 
        //   });
        var dataFromCache = wx.getStorageSync('WordDetail');
  if (dataFromCache) {
    // 使用缓存数据
    console.log(dataFromCache);
  }
        } catch (e) {
          wx.showToast({
            title: '数据存储失败',
            icon: 'none',
            duration: 2000
          });
        }
      },


    
  
    deleteItem: function(e) {
      var that = this
      var userId = this.data.userInfo.uuid
      var index = e.currentTarget.dataset.index
      var list = this.data.wordList
      var wordId = this.data.wordList[index].word_id
      //执行删除动画
      this.leftSlideGroup.deleteChild(index, function () {
        wx.request({
            url: 'http://47.95.223.130:8083/Custom/del',
            method: 'POST',
            data: {
              userId: userId, 
              word: JSON.stringify(that.data.wordList[index]),
              word_id: wordId
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            success: function(res){
              if (res.data.code === 200) {
                console.log(res)
                //动画执行完毕，更新数据
                list.splice(index, 1)
                that.setData({
                    wordList: list
                })
                console.log("删除成功: " + wordId)
              }
            },
            fail: function(err) {
              console.log(err)
            }
          });
      });
      
    },
      
      //其他页面代码...
  
  })
